/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.base;


import dex.misc.Augmented;
import dex.misc.Mirror;


/**
 * Base class for all nodes in a parse tree.
 */
public abstract class ParseNode extends Augmented<ParseNode> {
	

	/**
	 * The place where this node originated.
	 */
	final private Place place;
	
	
	/**
	 * Constructs a new parse node that originated at the given place.
	 * 
	 * @param place  the place where this node originated
	 */
	public ParseNode(Place place) {
		if (place == null) {
			throw new IllegalArgumentException("place may not be null");
		}
		this.place = place;
	}
	
	
	/**
	 * Returns the place where this node originated.
	 * 
	 * @return  the origin of this node
	 */
	public Place getPlace() {
		return place;
	}

	
	/**
	 * Returns this node expressed as Dex code.
	 *
	 * @return  this node expressed as Dex code
	 */
	public abstract String toString();

	
	/**
	 * Returns true if the given object equals this parse node.
	 * The given object must be of the exact same type as this
	 * parse node, and have equal members.
	 * 
	 * @param o  the object to test
	 * @return  true if the object is equal to this parse node
	 */
	public boolean equals(Object o) {
		return Mirror.equals(this, o);
	}

	
	/**
	 * Returns a hash code for this node.
	 * 
	 * @return  a hash code for this node
	 */
	public int hashCode() {
		return Mirror.hashCode(this);
	}

}
